




alter   function [dbo].[f_currdtof](@moneyid int, @exchrate decimal(18,8), @dcamount decimal(18,8))
returns decimal(18,8)
as
begin
  declare @amount decimal(18,8),@calctype int,@rate decimal(18,8)
  set @amount=0
  if (isnull(@exchrate,0) = 0) 
    return @amount
  if isnull(@moneyid,0) = 0 
    return @dcamount 
  select @calctype=calctype,@rate=rate from td_money where moneyid=@moneyid
  if @exchrate=-1
    set @exchrate=@rate
  if (@calctype = 0) 
    set @amount = round(@dcamount / @exchrate,8)
  else if (@calctype = 1) 
    set @amount = round(@dcamount * @exchrate,8)
  return @amount
end









